package cn.lbf.stuniversity.equipmenttype.controller;

import cn.lbf.stuniversity.equipmenttype.form.EquipTypeDetailForm;
import org.springframework.data.domain.Page;
import cn.lbf.stuniversity.equipmenttype.entity.EquipmentType;
import cn.lbf.stuniversity.equipmenttype.entity.EquipmentTypeTreeNode;
import cn.lbf.stuniversity.equipmenttype.form.EquipTypeAddForm;
import cn.lbf.stuniversity.equipmenttype.form.EquipTypeForm;
import cn.lbf.stuniversity.equipmenttype.service.EquipmentTypeService;
import cn.lbf.stuniversity.vo.Result;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;
@RestController
@RequestMapping("/equipType")
@CrossOrigin
public class EquipmentTypeController {
    @Autowired
    private EquipmentTypeService equipmentTypeService;
    @PostMapping("/addNew")
    public Result<Map<String,Object>> addNew(@Valid @RequestBody EquipTypeAddForm form){
        return equipmentTypeService.addNew(form);
    }
    @GetMapping("/typeTree")
    public List<EquipmentTypeTreeNode> getEquipmentTypeTree() {
        return equipmentTypeService.getEquipmentTypeTree();
    }
    @GetMapping("/queryList")
    public Result<Page<EquipmentType>> queryList(@Valid EquipTypeForm form){
        System.out.println(form);
        return equipmentTypeService.queryList(form);
    }

    @GetMapping("/del")
    public Result<String> del(String equipmentTypeId){
        return equipmentTypeService.del(equipmentTypeId);
    }

    @PostMapping("/edit")
    public Result<String> edit(@Valid @RequestBody EquipTypeDetailForm form){
        return equipmentTypeService.updateByEquipmentTypeId(form);
    }
}
